'''
Created on 2015-3-16

@author: xizhzhao
'''
from DataFetcher import *
import json
import abc
from Logger import *

class JsonDataFetcher(DataFetcher):
    __metaclass__ = abc.ABCMeta
    
    def init(self, url, recurse=False):
        DataFetcher.init(self, url, True)

    def preFectch(self, params, headers): return

    def fetch(self):
        DataFetcher.fetch(self)
        self.__json_data__ = None
        if self.__data_src__ != None:
           # Process the json data first
           self.preProcess()
           try:
               self.__json_data__ = json.loads(self.__data_src__)
           except Exception as e:
               global logger
               logger.info(str(e))
               return False
        
        return True      

    @abc.abstractmethod
    def preProcess(self):
        # self.__data_src__ = self.__data_src__[10:len(self.__data_src__) - 2]
        return
